<template>
  <div class="app-container">
    <el-dialog :title="'选择船舶'" append-to-body
               :visible.sync="isShowShip"
               :close-on-click-modal="false"
               width="80%"
               class="dialog_collect"
               @open="handleOpenDialog"
               @close="handleCloseDialog">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="船名" prop="shipName">
          <el-input
            v-model="queryParams.shipName"
            placeholder="请输入船名"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="船舶编码" prop="shipCode">
          <el-input
            v-model="queryParams.shipCode"
            placeholder="请输入船舶编码"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="shipList">
        <el-table-column label="主建id" align="center" prop="id" v-if="false"/>
        <el-table-column label="数据状态" align="center" prop="state"/>
        <el-table-column label="船名" align="center" prop="shipName"/>
        <el-table-column label="船舶所有人名称" align="center" prop="pensionName"/>
        <el-table-column label="船舶编码" align="center" prop="shipCode"/>
        <el-table-column label="船长" align="center" prop="captain"/>
        <el-table-column label="辖区代码" align="center" prop="jurisdictionCode"/>
        <el-table-column label="主机总功率" align="center" prop="power"/>
        <el-table-column label="作业类型" align="center" prop="workType"/>
        <el-table-column label="联系电话" align="center" prop="contactNumber"/>
        <el-table-column label="所有人证件号" align="center" prop="certificateNumber"/>
        <el-table-column label="船舶类型" align="center" prop="shipType" :formatter="shipTypeFormat"/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleSave(scope.row)"
              v-hasPermi="['basicInformation:appUser:edit']"
            >下派
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <section slot="footer" class="dialog-footer">
        <el-button @click="handleCloseDialog">关 闭</el-button>
      </section>
    </el-dialog>
  </div>
</template>

<script>
  import { currentPoint } from '@/api/basicInformation/ship'

  export default {
    name: 'Ship',
    components: {},
    props: {
      isShowShip: {
        type: Boolean,
        default: false
      },
      runBoatList: {
        type: Object,
        default: () => {
          return {}
        }
      }
    },
    watch: {
      runBoatList: {
        handler(val) {
          this.queryParams = this.runBoatList
        }
      }
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 船舶信息表格数据
        shipList: [],
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        // 船舶类型字典
        shipTypeOptions: [],
        // 查询参数
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          shipType: '2',
          maxX: 0,
          maxY: 0,
          minX: 0,
          minY: 0,
          shipName: undefined,
          shipCode: undefined
        }
      }
    },
    methods: {
      handleOpenDialog() {
        this.getList()
        this.getDicts('ship_type').then(response => {
          this.shipTypeOptions = response.data
        })
      },
      handleCloseDialog() {
        this.$emit('closeDialog', 'boat')
      },
      /** 查询船舶信息列表 */
      getList() {
        this.loading = true
        currentPoint(this.queryParams).then(response => {
          this.shipList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      // 船舶类型字典翻译
      shipTypeFormat(row, column) {
        return this.selectDictLabel(this.shipTypeOptions, row.shipType)
      },
      // 取消按钮
      cancel() {
        this.open = false
        this.reset()
      },
      // 表单重置
      reset() {
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          shipType: '2',
          shipName: undefined,
          shipCode: undefined,
          maxX: 0,
          maxY: 0,
          minX: 0,
          minY: 0,
        }
        this.resetForm('form')
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      handleSave(row) {

        this.handleCloseDialog()
      }
    }
  }
</script>
<style lang="scss" scoped>
  ::v-deep .el-dialog__footer {
    text-align: center;
    position: absolute;
    left: 0;
    right: 0;
    bottom: -65px;
    padding: 15px;
    background: #f1f1f1;
  }
</style>
